<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.stms.action.Stms9002ActionBean"%>
<%@page import="com.feib.stms.pagination.PaginatedList"%>
<%
// 欄位排序處理
Stms9002ActionBean actionBean = (Stms9002ActionBean) request.getAttribute("actionBean");
if (null != actionBean && null != actionBean.getQueryResult())
{
	PaginatedList queryResult = actionBean.getQueryResult();
	int sortDirection = queryResult.getSortDirection();  //2 : ascending, else: descending
	String sortSpan = "<span class=\"ui-icon ui-icon-circle-triangle-n\"></span>"; //由小到大
	if (1 == sortDirection)
	{
		sortSpan = "<span class=\"ui-icon ui-icon-circle-triangle-s\"></span>"; //由大到小
	}
	
	String sortCriterion = queryResult.getSortCriterion();
	if (null != sortCriterion && 0 != sortCriterion.length())
	{
		if ("parentMenuItemActionName".equalsIgnoreCase(sortCriterion))
		{
			pageContext.setAttribute("parentMenuItemActionNameSortedClass", 1==sortDirection?"sortDesc":"sortAsc");
			pageContext.setAttribute("parentMenuItemActionNameSortedSpan", sortSpan);
		}
		else if ("todoActionName".equalsIgnoreCase(sortCriterion))
		{
			pageContext.setAttribute("todoActionNameSortedClass", 1==sortDirection?"sortDesc":"sortAsc");
			pageContext.setAttribute("todoActionNameSortedSpan", sortSpan);
		}
		else if ("count".equalsIgnoreCase(sortCriterion))
		{
			pageContext.setAttribute("countSortedClass", 1==sortDirection?"sortDesc":"sortAsc");
			pageContext.setAttribute("countSortedSpan", sortSpan);
		}
	
	}
	
	// 上下頁鈕處理
	int lastPageNumber = queryResult.getTotalPageCount();
	int currentPageNumber = queryResult.getPageNumber();
	int prePageNumber = currentPageNumber - 1;
	int nextPageNumber = currentPageNumber + 1;
	
	pageContext.setAttribute("lastPageNumber", new Integer(lastPageNumber));
	pageContext.setAttribute("currentPageNumber", new Integer(currentPageNumber));
	pageContext.setAttribute("prePageNumber", new Integer(prePageNumber));
	pageContext.setAttribute("nextPageNumber", new Integer(nextPageNumber));
} // end of if (null != actionBean && null != actionBean.getQueryResult())

%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
            
    <script type="text/javascript">
    <!-- 
    $(document).ready(function() {
    

	<c:if test="${null != actionBean.queryResult && not empty actionBean.queryResult.paginatedList}">
		
		$("[id^='viewDetail-']").click(function() {
			var action = this.id.substring(11);
			  window.location = action;
 
		});
		
		$("[id^='a-sortHeader-']").click(function() {
			var sortField = this.id.substring(13);
			$('#hidden\\.queryResult\\.sortCriterion').val(sortField);
			
			var clazz = $(this).attr('class');
			if (null == clazz || 0 == clazz.length){
				$('#hidden\\.queryResult\\.sortDirection').val('1');
			
				}
			else if ('sortAsc' == clazz)
				$('#hidden\\.queryResult\\.sortDirection').val('1');
			else
				$('#hidden\\.queryResult\\.sortDirection').val('2');
				
		   var c=	$('#hidden\\.queryResult\\.sortDirection').val();
				
				
			$('#hidden\\.queryResult\\.pageNumber').val('1');
				
			$("#hidden\\.doQueryBtn").trigger('click');
			
		});
		
		$("[id^='firstPageBtn']").click(function() {
			$('#hidden\\.queryResult\\.pageNumber').val('1');
			$("#hidden\\.doQueryBtn").trigger('click');
		});
		
		$("[id^='prePageBtn']").click(function() {
			$('#hidden\\.queryResult\\.pageNumber').val('<c:out value="${prePageNumber}"/>');
			$("#hidden\\.doQueryBtn").trigger('click');
		});
		
		$("[id^='nextPageBtn']").click(function() {
			$('#hidden\\.queryResult\\.pageNumber').val('<c:out value="${nextPageNumber}"/>');
			$("#hidden\\.doQueryBtn").trigger('click');
		});
		
		$("[id^='lastPageBtn']").click(function() {
			$('#hidden\\.queryResult\\.pageNumber').val('<c:out value="${lastPageNumber}"/>');
			$("#hidden\\.doQueryBtn").trigger('click');
		});
		
		$("[id^='currentPageText']").change(function() {
			var value = this.value;
			if (value != ''){
				value = value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
				var intRegex = /^\d+$/;
				if(!intRegex.test(value)) {
					showErrorMessageDialog('頁數必須是整數');
					return ;
				}
				
				value = parseInt(value, 10);
				
				if (value < 1){
					showErrorMessageDialog('頁數必須是大於1');
					return ;
				}
				else if (value > <c:out value='${lastPageNumber}'/>){
					showErrorMessageDialog('頁數必須是小於總頁數 (<c:out value="${lastPageNumber}"/>)');
					return ;
				}
				else if (value != <c:out value='${currentPageNumber}'/>){
					doQueryAction();
					$('#hidden\\.queryResult\\.pageNumber').val(value);
					$("#hidden\\.doQueryBtn").trigger('click');
				}
				
			}
			else{
				showErrorMessageDialog('頁數不可為空白)');
				return ;
			}
		});
</c:if>
		
		<c:if test="${not empty actionBean.message}">
    	showMessageDialog('<c:out value="${actionBean.message }" escapeXml="false"/>');
    	</c:if>
 });
    
    function doPrintEvent()
    {
    	divPrint('listForm');
    	return false;
    }
    
    //-->
    </script>
</head>
<body>

	<div id="smallQueryForm"></div>

	<div id="queryForm"></div>
	<div id="listForm">
	

		
		<div id="paginationBar" div stryle=" margin: 0 auto;"  >
			<input type="button" id="firstPageBtn" class="formBtn" value="第一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
			<input type="button" id="prePageBtn" class="formBtn" value="上一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
			第 <input type="text" id="currentPageText" class="formBtn" value="${currentPageNumber }" size="3" maxlength="4"> / ${lastPageNumber} 頁
			<input type="button" id="nextPageBtn" class="formBtn" value="下一頁" <c:out value='${lastPageNumber<nextPageNumber ? "disabled": "" }'/> />
			<input type="button" id="lastPageBtn" class="formBtn" value="最末頁" <c:out value='${lastPageNumber<=currentPageNumber ? "disabled": "" }'/> />
		</div>
                <table id="queryResultTable">
                 <thead>
          
                    
                    <tr>
                      
                        <th><a id='a-sortHeader-parentMenuItemActionName' href='javascript:void(0);' class="<c:out value='${parentMenuItemActionNameSortedClass}'/>"> <c:out value='${parentMenuItemActionNameSortedSpan }' escapeXml="false"/>待辦模組</a> </th>                 
                        <th><a id='a-sortHeader-todoActionName' href='javascript:void(0);' class="<c:out value='${todoActionNameSortedClass}'/>"> <c:out value='${todoActionNameSortedSpan }' escapeXml="false"/>待辦事項</a></th>
                        <th><a id='a-sortHeader-count' href='javascript:void(0);' class="<c:out value='${countSortedClass}'/>"><c:out value='${countSortedSpan }' escapeXml="false"/>檔案數</a></th>
                        <th>前往處理</th>
                    </tr>
                    </thead>
<c:choose>				
<c:when test="${null != actionBean.queryResult && not empty actionBean.queryResult.paginatedList}">
                    <tbody>
                    <c:forEach items="${actionBean.queryResult.paginatedList}" var="viewObj" varStatus="rowstat">
                    <tr>
                     
                        <td align="center"><c:out value="${viewObj.parentMenuItemActionName}" /></td>
                        <td align="center"><c:out value="${viewObj.todoActionName}" /></td>
                        <td align="center"><c:out value="${viewObj.count}" /></td>                     
                        <td>  
                        <div id="viewDetail-<c:url value='${viewObj.targetActionPage}'/>" class="widgetsIcon ui-state-default ui-corner-all" title="檢視"><span class="ui-icon ui-icon-circle-triangle-e"></span></div>
                        </td>
                    </tr>                 
                    </c:forEach>
                    </tbody>
                    <tfoot>
                    <tr>
                        <td colspan="8" class="listFunction"><input type="button" value="列印" onclick="javascript:doPrintEvent();" class="formBtn"/></td>
                    </tr>
                    </tfoot>
 </c:when>	
	<c:otherwise>
  		<tbody>
  				 <tr>
   					<td colspan="15" align="center" >查無資料</td>
   				</tr>
  		</tbody> 
	</c:otherwise>	
</c:choose>	
        
                </table>

                
	</div>

<div style="display: none;">
<stripes:form id="hidden.queryuploadFileTodoListFrom" beanclass="com.feib.stms.action.Stms9002ActionBean" method="post" onsubmit="javascript: waitingDialog({});">
	<stripes:hidden id="hidden.queryResult.pageNumber" name="queryResult.pageNumber" />
	<stripes:hidden id="hidden.queryResult.sortCriterion" name="queryResult.sortCriterion" />
	<stripes:hidden id="hidden.queryResult.sortDirection" name="queryResult.sortDirection" />
	<stripes:submit id="hidden.doQueryBtn" name="doQuery" value="查詢" class="formBtn"/>
	<stripes:errors></stripes:errors>
</stripes:form>
</div>

</body>
</html>
